
$(document).ready(function(){
	var rootPath = getRootPath();
	var potentialUserId = getQueryParamValue("potentialUserId");
	$("#potentialUserId").val(potentialUserId);
	function fn(){
	      if(confirm("您还没有设定专属服务顾问，快去设定吧！")){
	          location.href="selectCounselor.html?potentialUserId="+potentialUserId+"&positionId=602";
	      }else{
	          
	      }
	}
	//销售顾问
	$.ajax({
		method : 'get',
		url : rootPath+'/wechat/api/potentialUsers/counselor/selectSalesCounselor',
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("连接服务器错误!");
		},
		success : function(resultData){
			var saleHtml = '';
			if(resultData==null||resultData==''){
				saleHtml = saleHtml 	+ '<p><span><br><br><br>'
										+ '<button type="button" class="btn btn-info btn-block" onclick="saleBtn()">'
										+ '<span class="glyphicon glyphicon-plus-sign"></span>'
										+ '<span style="font-family:宋体;font-size:15px;">添加专属销售顾问</span>'
										+ '</button>'
										+ '</span></p><br>'
			}else{
			$.each(resultData,function(salesCounselorIndex,salesCounselorObj){
				var salesCounselorHtml = '';
				
				saleName = salesCounselorObj.userName;
				salePhone = salesCounselorObj.phone;
				
				if(salesCounselorObj.iconsPhoto==null){
					saleicoPhoto = "../../images/touxiang.png";
				}else{
					saleicoPhoto = salesCounselorObj.iconsPhoto;
				}

				salesCounselorHtml = salesCounselorHtml+'<p><span><br>'
													   +'<img id="saleicoPhoto" class="img-circle" src="'+ saleicoPhoto +'" alt="头像" title="头像图片" style="width:100px;height:100px"/>'
													   +'</span></p>'
													   +'<p><span id="saleName">'+ saleName +'</span></p>'
													   +'<a href="tel:'+ salePhone +'" id="saleTel">'
													   +'<button type="button" class="btn btn-default btn-sm">'
													   +'<span class="glyphicon glyphicon-earphone" style="color: rgb(255, 0, 0);"></span>'
													   +'<span id="salePhone">'+ salePhone +'</span>'
													   +'</button><br><br>'
													   +'</a> '
				saleHtml += salesCounselorHtml;
				
				//$("#saleName").html(saleName);
				//$("#salePhone").html(salePhone);
				//$("#saleTel").attr("href","tel:"+salePhone);
			});
			}
			$("#salesCounselorHtml").append(saleHtml);
		}
	});
	
	//售后顾问
	$.ajax({
		method : 'get',
		url : rootPath+'/wechat/api/potentialUsers/counselor/selectAfterSaleCounselor',
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("连接服务器错误!");
		},
		success : function(resultData){
			var wholeHtml = '';
			
			if(resultData==null||resultData==''){
				fn();
				wholeHtml = wholeHtml 	+ '<p><span><br><br><br>'
										+ '<button type="button" class="btn btn-info btn-block" onclick="afterSaleBtn()">'
										+ '<span class="glyphicon glyphicon-plus-sign"></span>'
										+ '<span style="font-family:宋体;font-size:15px;">添加专属售后顾问</span>'
										+ '</button>'
										+ '</span></p><br>'
			}else{
			$.each(resultData,function(afterSaleCounselorIndex,afterSaleCounselorObj){
				var afterSalesCounselorHtml = '';
				
				afterSaleName = afterSaleCounselorObj.userName;
				afterSalePhone = afterSaleCounselorObj.phone;
				
				if(afterSaleCounselorObj.iconsPhoto==null){
					afterSaleicoPhoto = "../../images/touxiang.png";
				}else{
					afterSaleicoPhoto = afterSaleCounselorObj.iconsPhoto;
				}
				
				afterSalesCounselorHtml = afterSalesCounselorHtml + '<p><span><br>'
																  + '<img id="afterSaleicoPhoto" class="img-circle" src="'+ afterSaleicoPhoto +'" alt="头像" title="头像图片" style="width:100px;height:100px"/>'
																  + '</span></p>'
																  + '<p><span id="afterSaleName">'+ afterSaleName +'</span></p>'
																  + '<a href="tel:'+ afterSalePhone +'" id="afterSaleTel">'
																  + '<button type="button" class="btn btn-default btn-sm">'
																  + '<span class="glyphicon glyphicon-earphone" style="color: rgb(255, 0, 0);"></span>'
																  + '<span id="afterSalePhone">'+ afterSalePhone +'</span>'
																  + '</button><br><br>'
																  + '</a>'	
			    wholeHtml += afterSalesCounselorHtml;

				//$("#afterSaleName").html(afterSaleName);
				//$("#afterSalePhone").html(afterSalePhone);
				//$("#afterSaleTel").attr("href","tel:"+afterSalePhone);
			});
		  }
			$("#afterSalesCounselorHtml").append(wholeHtml);
		}
	});
})
